#include "Comm.hpp"
#include"Fifo.hpp"

int main()
{


    key_t key = GetShmKeyOrDie();
    cout<<ToHex(key)<<endl;
    int shmid = CreateShm(key,defaultsize);
    cout<<"shmid:"<<shmid<<endl;
    
    //ShmDebug(shmid);
    // 挂接共享内存
    char* shmAddr = (char*)ShmAttach(shmid);
    if(shmAddr == nullptr)
    {
        cerr<<"shmAttach error"<<endl;
        return -1;
    }
    cout<<"shmaddr"<<ToHex((uint64_t)shmAddr)<<endl;

    Fifo fifo;
    Sync syn;
    syn.OpenReadOrDie();
    // 开始通信 
    while(true)
    {
         // 先等.
        if(!syn.Wait()) break;
        cout<<"shmclient content:"<<shmAddr<<endl;      
    }
    // 去关联
    ShmDetach(shmAddr);
    cout<<"shmDetach success!!"<<endl;
    
    // 删除共享内存.
    DeleteShm(shmid);
    return 0;
}